<template>
  <view class="search-page">
    <!-- 顶部栏 -->
    <view class="header">
      <text class="back" @click="onBack">&#60;</text>
      <text class="title">药品搜索</text>
    </view>

    <!-- 搜索框 -->
    <view class="search-bar">
      <text class="search-icon">🔍</text>
      <input
        class="search-input"
        v-model="searchText"
        placeholder="请输入药名/条码/制药厂 搜索药品"
      />
    </view>

    <!-- 历史记录框 -->
    <view class="history-box">
      <view class="history-title-row">
        <text class="history-title">大家在搜</text>
        <view class="history-underline"></view>
      </view>
      <view class="history-list">
        <view
          class="history-item"
          v-for="item in historyList"
          :key="item"
          @click="onHistoryClick(item)"
        >
          <text class="history-icon">🩺</text>
          <text class="history-text">{{ item }}</text>
        </view>
      </view>
    </view>

    <!-- 大家在搜热门搜索 -->
    <view class="hot-title">大家在搜</view>
    <view class="hot-list">
      <view
        class="hot-item"
        v-for="item in hotList"
        :key="item"
        @click="onHotClick(item)"
      >
        <text class="hot-text">{{ item }}</text>
        <button class="hot-btn" @click.stop="onBaiduSearch(item)">百度</button>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from "vue";

const searchText = ref("");
const historyList = ref([
  "布洛芬缓释胶囊",
  "板蓝根",
  "六味地黄丸",
  "小儿肠胃康颗粒",
  "藿香正气水",
]);
const hotList = ref([
  "阿莫西林",
  "布洛芬",
  "感冒灵",
  "头孢克肟",
  "维生素C",
  "青霉素",
  "地塞米松",
  "氯雷他定",
]);

const onBack = () => {
  uni.navigateBack();
};
const onHistoryClick = (item: string) => {
  searchText.value = item;
};
const onHotClick = (item: string) => {
  searchText.value = item;
};
const onBaiduSearch = (item: string) => {
  const url = `https://www.baidu.com/s?wd=${encodeURIComponent(item)}`;
  // #ifdef H5
  window.open(url, "_blank");
  // #endif
  // #ifndef H5
  uni.navigateTo({
    url: `/pages/webview/webview?url=${encodeURIComponent(url)}`,
  });
  // #endif
};
</script>

<style scoped>
.search-page {
  background: #fff;
  min-height: 100vh;
  padding: 32rpx 0 0 0;
}
.header {
  display: flex;
  align-items: center;
  height: 100rpx;
  background: #fff;
  box-shadow: 0 8rpx 24rpx rgba(25, 195, 60, 0.08);
  padding: 0 32rpx;
  position: relative;
}
.back {
  font-size: 48rpx;
  color: #19c37c;
  font-weight: bold;
  margin-right: 24rpx;
  cursor: pointer;
}
.title {
  font-size: 36rpx;
  color: #19c37c;
  font-weight: bold;
}
.search-bar {
  display: flex;
  align-items: center;
  margin: 0 32rpx 24rpx 32rpx;
  background: #fff;
  border-radius: 16rpx;
  box-shadow: 0 2rpx 8rpx rgba(25, 195, 60, 0.1);
  border: 3rpx solid #19c37c;
  padding: 0 24rpx;
  height: 80rpx;
}
.search-icon {
  font-size: 36rpx;
  color: #19c37c;
  margin-right: 16rpx;
}
.search-input {
  flex: 1;
  border: none;
  background: none;
  font-size: 28rpx;
  color: #888;
  outline: none;
  background: transparent;
}
.history-box {
  margin: 0 24rpx;
  background: linear-gradient(90deg, #19c37c 0%, #29e6ff 100%);
  border-radius: 32rpx;
  padding: 24rpx 24rpx 16rpx 24rpx;
  box-sizing: border-box;
}
.history-title-row {
  display: flex;
  align-items: flex-end;
  margin-bottom: 16rpx;
}
.history-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #222;
  font-style: italic;
  margin-right: 12rpx;
}
.history-underline {
  width: 48rpx;
  height: 8rpx;
  background: #fff;
  border-radius: 4rpx;
  margin-bottom: 6rpx;
}
.history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 20rpx 24rpx;
}
.history-item {
  display: flex;
  align-items: center;
  background: transparent;
  border: 2rpx solid #fff;
  border-radius: 12rpx;
  padding: 0 24rpx;
  height: 56rpx;
  color: #fff;
  font-size: 26rpx;
  margin-bottom: 12rpx;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.history-item:active {
  background: #fff;
  color: #19c37c;
}
.history-icon {
  font-size: 26rpx;
  margin-right: 8rpx;
}
.history-text {
  font-size: 26rpx;
}
.hot-title {
  font-size: 28rpx;
  color: #19c37c;
  font-weight: bold;
  margin: 40rpx 32rpx 16rpx 32rpx;
}
.hot-list {
  margin: 0 32rpx;
  display: flex;
  flex-direction: column;
  gap: 24rpx;
}
.hot-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8f8f8;
  border-radius: 12rpx;
  padding: 24rpx 20rpx;
  box-shadow: 0 2rpx 8rpx rgba(25, 195, 60, 0.04);
  cursor: pointer;
  transition: background 0.2s;
}
.hot-item:active {
  background: #e0fbe6;
}
.hot-text {
  font-size: 28rpx;
  color: #333;
}
.hot-btn {
  background: #19c37c;
  color: #fff;
  font-size: 26rpx;
  border: none;
  border-radius: 8rpx;
  padding: 0 24rpx;
  height: 48rpx;
  line-height: 48rpx;
  margin-left: 24rpx;
}
</style> 